import { ApiProperty, getSchemaPath } from "@nestjs/swagger";
import { CrudValidationGroups } from "@nestjsx/crud";
import { IsNumber, IsString } from "class-validator";
import { Column, Entity, OneToOne, PrimaryGeneratedColumn } from "typeorm";
import { Assets } from "./assets.entity";
import { BaseEntity } from "./base.entity";

const { CREATE, UPDATE } = CrudValidationGroups;


@Entity()
export class NonOperatingAssets extends BaseEntity {
  
  @ApiProperty({
    description: '非经营性资产主键',
    required: false
  })
  @PrimaryGeneratedColumn()
  id ?: number;

  @ApiProperty({
    example: '计量单位',
    description: '计量单位',
  })
  @IsString({ always: true })
  @Column({
    type: "char",
    length: 255,
    nullable: true,
  })
  unitOfMeasurement ?: string

  @ApiProperty({
    example: 1,
    description: '数量',
    required: true
  })
  @IsNumber({}, { always: true })
  @Column({
    nullable: true,
  })
  quantity ?: number


  @ApiProperty({
    example: 1,
    description: '单价(注意前端注明单位)',
    required: true
  })
  @IsNumber({}, { always: true })
  @Column({
    nullable: true,
  })
  unitPrice ?: number

  @ApiProperty({
    example: '变动情况',
    description: '变动情况',
    required: true
  })
  @IsString({ always: true })
  @Column({
    type: "char",
    length: 255,
    nullable: true,
  })
  changes ?: string

  @ApiProperty({
    example: 1,
    description: '现今价值',
    required: true
  })
  @IsNumber({}, { always: true })
  @Column({
    nullable: true,
  })
  presentValue ?: number

  @ApiProperty({
    example: '品牌',
    description: '品牌',
    required: true
  })
  @IsString({ always: true })
  @Column({
    type: "char",
    length: 255,
    nullable: true,
  })
  brand ?: string

  @ApiProperty({
    example: '规格型号',
    description: '规格型号',
    required: true
  })
  @IsString({ always: true })
  @Column({
    type: "char",
    length: 255,
    nullable: true,
  })
  sizeAndModel ?: string

  @ApiProperty({
    example: '构建时间',
    description: '构建时间',
    required: true,
  })
  @IsString()
  @Column({
    type: "date",
    nullable: true,
  })
  creationTime ?: Date

  @ApiProperty({
    example: '产品来源',
    description: '产品来源',
    required: true
  })
  @IsString({ always: true })
  @Column({
    type: "char",
    length: 255,
    nullable: true,
  })
  source ?: string

  @ApiProperty({
    example: '预计年限',
    description: '预计年限',
    required: true
  })
  @IsString({ always: true })
  @Column({
    type: "char",
    length: 255,
    nullable: true,
  })
  estimatedYears ?: string
  
  @ApiProperty({
    example: '使用部门及使用者',
    description: '使用部门及使用者',
    required: true
  })
  @IsString({ always: true })
  @Column({
    type: "char",
    length: 255,
    nullable: true,
  })
  useDepartmentsAndUser ?: string


  @ApiProperty({
    example: '产品状态',
    description: '产品状态',
    required: true
  })
  @IsString({ always: true })
  @Column({
    type: "char",
    length: 255,
    nullable: true,
  })
  productStatus ?: string

  @ApiProperty({
    example: '备注',
    description: '备注',
    required: true
  })
  @IsString({ always: true })
  @Column({
    type: "text",
    nullable: true,
  })
  remarks ?: string

  @ApiProperty({
    example: {},
    description: '所属资产',
    required: false,
    oneOf: [
      {
        type: 'Number'
      }, 
      { $ref: getSchemaPath(() => Assets)}
    ]
  })
  @OneToOne(() => Assets, Assets => Assets.nonOperatingAssets, {
    eager: true
  })
  assets : () => Assets;
}

